package com.operation.utils;

import com.operation.beans.WorkOrderAllInfo;

import java.util.*;

public class ITDataUtil {
    public static Map wrapperData(List<WorkOrderAllInfo> obj) {
        Map<String, Integer> map;
        Map<String, Map<String, Integer>> map1;
        List<Map<String, Map<String, Integer>>> list1 = new ArrayList<>();
        List list2;
        List<List<Map<String, Integer>>> list3;
        Map map3 = new HashMap<>();
        Set<String> set = new HashSet<>();
        List<WorkOrderAllInfo> list = obj;
        for (WorkOrderAllInfo str : list) {
            set.add(str.getUserName());
        }
        for (int i = 0; i < set.size(); i++) {
            for (WorkOrderAllInfo str : list) {

                if (str.getUserName().equals(set.toArray()[i].toString())) {
                    map = new HashMap<>();
                    map1 = new HashMap<>();
                    map.put(str.getDetails(), str.getIsReceive());
                    map1.put(set.toArray()[i].toString(), map);
                    list1.add(map1);
                }

            }

        }
        for (int j = 0; j < set.size(); j++) {
            list2 = new ArrayList<>();
            list3 = new ArrayList<>();
            for (Map<String, Map<String, Integer>> map2 : list1) {
                if (map2.keySet().toString().trim().equals("[" + set.toArray()[j].toString().trim() + "]")) {
                    list2.add(map2.values());
                }
            }
            list3.add(list2);
            map3.put(set.toArray()[j].toString().trim(), list3);
        }
        return map3;
    }
}
